﻿// Shader-Based-Image-Processing (SBIP)
// http://code.google.com/p/sbip/
//
// Copyright © Frank Nagl, 2009-2010
// admin@franknagl.de
//
namespace SBIP.OptionsForms
{
    using System;
    using System.Windows.Forms;
    using Filter;

    /// <summary>Filter specified properties form.</summary>
    public partial class CannyForm : Form
    {
        private readonly CannyEdgeDetector filter;

        /// <summary>
        /// Initializes a new instance of the <see cref="SobelForm"/> class.
        /// </summary>
        /// <param name="processor">The processor.</param>
        public CannyForm(Processor processor)
        {
            InitializeComponent();
            filter = new CannyEdgeDetector();
            processor.Filter = filter;
        }

        private void RdbtnGrayscaleCheckedChanged(object sender, EventArgs e)
        {
            if (((RadioButton)sender).Checked)
            {
                filter.BlackWhite = false;
            }
        }

        private void RdbtnMonochromeCheckedChanged(object sender, EventArgs e)
        {
            if (((RadioButton)sender).Checked)
            {
                filter.BlackWhite = true;
            }
        }

        private void RdbtnBt709CheckedChanged(object sender, EventArgs e)
        {
            if (((RadioButton)sender).Checked)
            {
                filter.GrayscaleAlgorithm = Grayscale.CommonAlgorithms.BT709;
            }
        }

        private void RdbtnRmyCheckedChanged(object sender, EventArgs e)
        {
            if (((RadioButton)sender).Checked)
            {
                filter.GrayscaleAlgorithm = Grayscale.CommonAlgorithms.RMY;
            }
        }

        private void RdbtnYCheckedChanged(object sender, EventArgs e)
        {
            if (((RadioButton)sender).Checked)
            {
                filter.GrayscaleAlgorithm = Grayscale.CommonAlgorithms.Y;
            }
        }

        private void RdbtnLightCheckedChanged(object sender, EventArgs e)
        {
            if (((RadioButton)sender).Checked)
            {
                filter.Version = FixedGaussianBlur.Versions.Light;
            }
        }

        private void RdbtnStrongCheckedChanged(object sender, EventArgs e)
        {
            if (((RadioButton)sender).Checked)
            {
                filter.Version = FixedGaussianBlur.Versions.Strong;
            }
        }

        private void TrbarHighThresholdValueChanged(object sender, EventArgs e)
        {
            filter.HighThreshold = (byte)trbarHighThreshold.Value;
            lbHighThreshold.Text = trbarHighThreshold.Value.ToString();
        }

        private void TrbarLowThresholdValueChanged(object sender, EventArgs e)
        {
            filter.LowThreshold = (byte)trbarLowThreshold.Value;
            lbLowThreshold.Text = trbarLowThreshold.Value.ToString();
        }

        private void TrbarMaxGradientValueChanged(object sender, EventArgs e)
        {
            filter.MaxGradient = trbarMaxGradient.Value / 10000.0f;
            lbMaxGradient.Text = (trbarMaxGradient.Value / 10000.0f).ToString();
        }
    }
}
